package com.bw.service.impl;

import com.bw.domain.*;
import com.bw.exception.MyRuntimeException;
import com.bw.mapper.OrderMapper;
import com.bw.service.OrderService;
import com.bw.utils.SmsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: Wrj
 * @Date: 2025/3/9 13:34
 * @Description:
 **/
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMapper orderMapper;

    @Override
    public List<Order> list(Order order) {
        return orderMapper.list(order);
    }

    @Override
    public List<Community> listCommunity() {
        return orderMapper.listCommunity();
    }

    @Override
    public List<Worker> listWorker() {
        return orderMapper.listWorker();
    }

    @Transactional(rollbackFor = MyRuntimeException.class)
    @Override
    public Boolean fp(Order order, String select) {

        try {


            orderMapper.updateOrder(order);

            orderMapper.instrOrderDetial(order.getId(),select);

            String[] split = select.split(",");
            for (String sp : split) {
                Worker worker=orderMapper.findworkerphone(sp);
                SmsUtil.sendCode(worker.getPhone(),"您有新的工单要处理","1",1);
                System.out.println("短信已经发送");
            }


            return true;
        }catch (MyRuntimeException e){
            e.printStackTrace();
            throw new MyRuntimeException("添加失败");
        }

    }

    @Override
    public Order listOrderById(Integer id) {
        return orderMapper.listOrderById(id);
    }

    @Override
    public List<OrderDetail> listORderDetail(Integer id) {
        return orderMapper.listORderDetail(id);
    }

    @Override
    public int instrPj(Pj pj) {
        return orderMapper.instrPj(pj);
    }

    @Override
    public List<Pj> listPj(Integer id) {
        return orderMapper.listPj(id);
    }

    @Override
    public List<Community> listcommunity() {
        return orderMapper.listcommunity();
    }

    @Override
    public List<Dict> listorderType() {
        return orderMapper.listorderType();
    }

    @Override
    public int add(Order order) {
        return orderMapper.add(order);
    }

    @Override
    public List<OrderReport> report(String startTime, String endTime, String groupId) {
        return orderMapper.report(startTime,endTime,groupId);
    }

    @Override
    public List<Dict> listgroup(String type) {
        return orderMapper.listgroup(type);
    }


}
